package com.yls.except.util.jstltag;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * jsp jstl时间格式转换标签
 * @author xusheng
 * @time 2015-5-15 下午2:59:41   
 * @version 1.0
 * @Description:  {}
 *
 */
public class DateTag extends TagSupport{
	private static final long serialVersionUID = -5533195439593347187L;
	private String value;
    @Override
    public int doStartTag() throws JspException {
        String vv = ""+value ;
        String s = null;
        if(vv == null || "".equals(vv)) {
        	vv = "0";
        }
        long time = Long.valueOf(vv)*1000;
        if(time <= 0) {
        	s="0";
        } else {
        	Calendar c = Calendar.getInstance();
        	c.setTimeInMillis(time);
        	SimpleDateFormat dateformat = new SimpleDateFormat("MM-dd HH:mm" );
        	s = dateformat.format(c.getTime());
        }
        try {
        	pageContext.getOut().write(s);
        } catch (IOException e) {
        	e.printStackTrace();
        }
        return super.doStartTag();
    }
    public void setValue(String value) {
        this.value = value;
    }
	public String getValue() {
		return value;
	}
}
